package com.future.hedongjun.mall.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.future.baselib.activity.BaseListFragment;
import com.future.hedongjun.home.adapter.TopicAdapter;
import com.future.hedongjun.home.bean.TopicBean;
import com.future.hedongjun.mall.adapter.GoodsAdapter;
import com.future.hedongjun.mall.bean.GoodsItem;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;

/**
 * @author jniu
 * @Email niuxiaoqi@hztianque.com
 * @time 2018/11/18
 */
public class MallListFragment extends BaseListFragment {

    private String categoryId;

    public static MallListFragment getInstance(String id){
        MallListFragment fragment = new MallListFragment();
        Bundle args = new Bundle();
        args.putString("id",id);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected BaseQuickAdapter getAdapter() {
        return new GoodsAdapter(null);
    }

    @Override
    protected RecyclerView.LayoutManager getLayoutManager() {
        return new GridLayoutManager(getContext(), 2);
    }

    @Override
    protected Type getTypeToken() {
        return new TypeToken<List<GoodsItem>>(){}.getType();
    }

    @Override
    protected TreeMap<String, String> getRequestParams() {
        TreeMap<String, String> map = new TreeMap<>();
        map.put("cate_id", categoryId);
        return map;
    }

    @Override
    protected String getPath() {
        return "/addons/litestore/api.goods/lists";
    }

    @Override
    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
        Bundle bundle = new Bundle();
        bundle.putString("id", ((GoodsItem) adapter.getData().get(position)).getGoods_id());
        startActivity(GoodsDetailActivity.class, bundle);
    }

    @Override
    protected void getBundleExtras(Bundle extras) {
        categoryId = extras.getString("id");
    }

    @Override
    protected void initView(View view, @Nullable Bundle savedInstanceState) {

    }
}
